﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Browser;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace DiscoveryLogic.UI.Charts
{
    public class VisualControl:VisualElement
    {
        #region const
        internal const string RootElementName = "RootElement";
        internal const string ShadowGridName = "ShadowGrid";
        internal const string ChartBorderName = "ChartBorder";
        internal const string ChartLightingBorderName = "ChartLightingBorder";
        internal const string BevelCanvasName = "BevalCanvas";
        internal const string ChartAreaGridName = "ChartAreaGrid";
        internal const string TopOuterPanelName = "TopOuterPane";
        internal const string TopOuterTitlePanelName = "TopOuterTitlePanel";
        internal const string TopOuterLegendPanelName = "TopOuterLegendPanel";
        internal const string BottomOuterPanelName = "BottomOuterPanel";
        internal const string BottomOuterLegendPanelName = "BottomOuterLegendPanel";
        internal const string BottomOuterTitlePanelName = "BottomOuterTitlePanel";
        internal const string LeftOuterPanelName = "LeftOuterPanelName";
        internal const string LeftOuterTitlePanelName = "LeftOuterTitlePanel";
        internal const string LeftOuterLegendPanelName = "LeftOuterLegendPanel";
        internal const string RightOuterPanelName = "RightOuterPanel";
        internal const string RightOuterLegendPanelName = "RightOuterLegendPanel";
        internal const string RightOuterTitlePanelName = "RightOuterTitlePanel";
        internal const string CenterOuterGridName = "CenterOuterGrid";
        internal const string CenterGridName = "CenterGrid";
        internal const string TopOffsetGridName = "TopOffsetGrid";
        internal const string LeftOffsetGridName = "LeftOffsetGrid";
        internal const string RightOffsetGridName = "RightOffsetGrid";
        internal const string BottomOffsetGridName = "BottomOffsetGrid";
        internal const string TopAxisGridName = "TopAxisGrid";
        internal const string TopAxisContainerName = "TopAxisContainer";
        internal const string TopAxisPanelName = "TopAxisPanel";
        internal const string TopAxisScrollBarName = "TopAxisScrollBar";
        internal const string LeftAxisGridName = "LeftAxisGrid";
        internal const string LeftAxisContainerName = "LeftAxisContainer";
        internal const string LeftAxisPanelName = "LeftAxisPanel";
        internal const string LeftAxisScrollBarName = "LeftAxisScrollBar";
        internal const string RightAxisGridName = "RightAxisGrid";
        internal const string RightAxisContainerName = "RightAxisContainer";
        internal const string RightAxisPanelName = "RightAxisPanel";
        internal const string RightAxisScrollBarName = "RightAxisScrollBar";
        internal const string BottomAxisGridName = "BottomAxisGrid";
        internal const string BottomAxisContainerName = "BottomAxisContainer";
        internal const string BottomAxisPanelName = "BottomAxisPanel";
        internal const string BottomAxisScrollBarName = "BottomAxisScrollBar";
        internal const string CenterInnerGridName = "CenterInnerGrid";
        internal const string InnerGridName = "InnerGrid";
        internal const string TopInnerPanelName = "TopInnerPanel";
        internal const string TopInnerTitlePanelName = "TopInnerTitlePanel";
        internal const string TopInnerLegendPanelName = "TopInnerLegendPanel";
        internal const string LeftInnerPanelName = "LeftInnerPanel";
        internal const string LeftInnerTitlePanelName = "LeftInnerTitlePanel";
        internal const string LeftInnerLegendPanelName = "LeftInnerLegendPanel";
        internal const string RightInnerPanelName = "RightInnerPanel";
        internal const string RightInnerTitlePanelName = "RightInnerTitlePanel";
        internal const string RightInnerLegendPanelName = "RightInnerLegendPanel";
        internal const string BottomInnerPanelName = "BottomInnerPanel";
        internal const string BottomInnerTitlePanelName = "BottomInnerTitlePanel";
        internal const string BottomInnerLegendPanelName = "BottomInnerLegendPanel";
        internal const string PlotAreaGridName = "PlotAreaGrid";
        internal const string PlotAreaScrollViewerName = "PlotAreaScrollViewer";
        internal const string PlotCanvasName = "PlotCanvas";
        internal const string PlotAreaShadowCanvasName = "PlotAreaShadowCanvas";
        internal const string DrawingCanvasName = "DrawingCanvas";
        internal const string CenterDockInsidePlotAreaPanelName = "CenterDockInsidePlotAreaPanel";
        internal const string CenterDockOutsidePlotAreaPanelName = "CenterDockOutsidePlotAreaPanel";
        internal const string ToolTipCanvasName = "ToolTipCanvas";
        #endregion

        #region events 

        #endregion

        #region fields
        internal bool _IsTemplateApplied;
        internal Grid _RootElement;
        internal Grid _ShadowGrid;
        internal Border _ChartBorder;
        internal Rectangle _ChartLightingBorder;
        internal Canvas _BevelCanvas;
        internal Grid _ChartAreaGrid;
        internal StackPanel _TopOuterPanel;
        internal StackPanel _TopOuterTitlePanel;
        internal StackPanel _TopOuterLegendPanel;
        internal StackPanel _BottomOuterPanel;
        internal StackPanel _BottomOuterTitlePanel;
        internal StackPanel _BottomOuterLegendPanel;
        internal StackPanel _LeftOuterPanel;
        internal StackPanel _LeftOuterTitlePanel;
        internal StackPanel _LeftOuterLegendPanel;
        internal StackPanel _RightOuterPanel;
        internal StackPanel _RightOuterTitlePanel;
        internal StackPanel _RightOuterLegendPanel;
        internal Grid _CenterGrid;
        internal Grid _CenterOuterGrid;
        internal Grid _TopOffsetGrid;
        internal Grid _BottomOffsetGrid;
        internal Grid _LeftOffsetGrid;
        internal Grid _RightOffsetGrid;
        internal Grid _TopAxisGrid;
        internal StackPanel _TopAxisContainer;
        internal StackPanel _TopAxisPanel;
        internal ScrollBar _TopAxisScrollBar;
        internal Grid _BottomAxisGrid;
        internal StackPanel _BottomAxisContainer;
        internal StackPanel _BottomAxisPanel;
        internal ScrollBar _BottomAxisScrollBar;
        internal Grid _LeftAxisGrid;
        internal StackPanel _LeftAxisContainer;
        internal StackPanel _LeftAxisPanel;
        internal ScrollBar _LeftAxisScrollBar;
        internal Grid _RightAxisGrid;
        internal StackPanel _RightAxisContainer;
        internal StackPanel _RightAxisPanel;
        internal ScrollBar _RightAxisScrollBar;
        internal Grid _CenterInnerGrid;
        internal Grid _InnerGrid;
        internal StackPanel _TopInnerPanel;
        internal StackPanel _TopInnerTitlePanel;
        internal StackPanel _TopInnerLegendPanel;
        internal StackPanel _BottomInnerPanel;
        internal StackPanel _BottomInnerTitlePanel;
        internal StackPanel _BottomInnerLegendPanel;
        internal StackPanel _LeftInnerPanel;
        internal StackPanel _LeftInnerTitlePanel;
        internal StackPanel _LeftInnerLegendPanel;
        internal StackPanel _RightInnerPanel;
        internal StackPanel _RightInnerTitlePanel;
        internal StackPanel _RightInnerLegendPanel;
        internal Grid _PlotAreaGrid;
        internal ScrollViewer _PlotAreaScrollViewer;
        internal Canvas _PlotCanvas;
        internal Canvas _PlotAreaShadowCanvas;
        internal Canvas _DrawingCanvas;
        internal StackPanel _CenterDockInsidePlotAreaPanel;
        internal StackPanel _CenterDockOutsidePlotAreaPanel;
        internal Canvas _ToolTipCanvas;
        internal ToolTip _ToolTip;
        #endregion

        #region ctor
        public VisualControl()
        {
            ToolTipEnabled = true;
        }
        #endregion

        #region props
        public static DependencyProperty ToolTipEnabledProperty =
            DependencyProperty.Register("ToolTipEnabled",
            typeof(bool), typeof(VisualControl), null);

        [ScriptableMember]
        public bool ToolTipEnabled
        {
            get { return ((bool)base.GetValue(ToolTipEnabledProperty)); }
            set { base.SetValue(ToolTipEnabledProperty, value); }
        }

        [ScriptableMember]
        public string ControlID { get; set; }

        internal  bool IsInDesignMode
        {
            get
            {
                return (!HtmlPage.IsEnabled);
            }
        }
        #endregion

        #region public methods
        public static string GetAbsolutePath(string path)
        {
            string baseUri = HtmlPage.Document.DocumentUri.ToString();
            Uri uri=new Uri(path, UriKind.RelativeOrAbsolute);
            if(uri.IsAbsoluteUri)
                return uri.AbsolutePath;
            else if(path.StartsWith("/"))
            {
                UriBuilder uriBuilder=new UriBuilder(baseUri);
                UriBuilder newUri=new UriBuilder(uriBuilder.Scheme, uriBuilder.Host, uriBuilder.Port, path);
                return newUri.ToString();
            }
            else
            {
                UriBuilder uriBuilder=new UriBuilder(baseUri);
                string sourcePath = uriBuilder.Path.Substring(0, uriBuilder.Path.LastIndexOf("/") + 1);
                UriBuilder newUri = new UriBuilder(uriBuilder.Scheme, uriBuilder.Host, uriBuilder.Port, sourcePath+path);
                return newUri.ToString();
            }
        }
        #endregion

        #region private methods

        #endregion
    }
}
